"""
Author: interset-wq
Build a hash table
"""

class HashTable:
    """Simple hash table"""

    def __init__(self):
        self.collection = {}

    def hash(self, key):
        """Hash function"""
        sum = 0
        for char in key:
            sum += ord(char)
        return sum


    def add(self, key, value):
        "Add a key-value pair"
        hashed_key = self.hash(key)
        if hashed_key not in self.collection:
            self.collection[hashed_key] = {}
        self.collection[hashed_key][key] = value 

    def remove(self, key):
        """Remove a pair of key-value"""
        hashed_key = self.hash(key)
        if hashed_key in self.collection:
            pair = self.collection[hashed_key]
            if len(pair) == 1:
                del self.collection[hashed_key]
            else:
                del self.collection[hashed_key][key]

    def lookup(self, key):
        """Get the value by key"""
        hashed_key = self.hash(key)
        if hashed_key in self.collection:
            return self.collection[hashed_key][key]


if __name__ == "__main__":
    table = HashTable()
    table.add('golf', 'sport')
    table.add('fcc', 'coding')
    table.add('cfc', 'chemical')
    print(table.lookup('golf'))
